package com.atguigu.springcloud.service;

import com.atguigu.springcloud.bind.MyOutBind;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author timiv
 */
@EnableBinding(MyOutBind.class)
@Slf4j
public class RabbitProvider {
    @Resource(name = MyOutBind.OUTPUT_1)
    private MessageChannel output;
    @Resource(name = MyOutBind.OUTPUT_2)
    private MessageChannel output2;

    /**
     * 发送消息
     * @return
     */
    public String send(){
        String serial = UUID.randomUUID().toString();
        log.info("生产者发送消息：{}",serial);
        Message<String> build = MessageBuilder.withPayload(serial).build();
        output.send(build);
        output2.send(build);
        return "success";
    }
}
